package com.jeecg.demo.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.log4j.Logger;



public class GetMSgByInterface {
    private static Logger logger = Logger.getLogger(GetMSgByInterface.class);
    public static String requestSendMsg(String phone,String code) {
    	String msg_url="http://172.16.103.134:8080/pay/mpsms/message/sendSms.do?signName=国联科技&templateCode=SMS_210850044";
    	msg_url=msg_url+"&"+"phoneNum="+phone+"&code="+code;
        String reuslt = httpRequest(msg_url,"GET",null);
        return reuslt;
    }
  //处理http请求  requestUrl为请求地址  requestMethod请求方式，值为"GET"或"POST"
    public static String httpRequest(String requestUrl,String requestMethod,String outputStr){
        StringBuffer buffer=null;
        try{
        URL url=new URL(requestUrl);
        HttpURLConnection conn=(HttpURLConnection)url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod(requestMethod);
        conn.connect();
        //往服务器端写内容 也就是发起http请求需要带的参数
        if(null!=outputStr){
            OutputStream os=conn.getOutputStream();
            os.write(outputStr.getBytes("utf-8"));
            os.close();
        }
        
        //读取服务器端返回的内容
        InputStream is=conn.getInputStream();
        InputStreamReader isr=new InputStreamReader(is,"utf-8");
        BufferedReader br=new BufferedReader(isr);
        buffer=new StringBuffer();
        String line=null;
        while((line=br.readLine())!=null){
            buffer.append(line);
        }
        }catch(Exception e){
            e.printStackTrace();
        }
        return buffer.toString();
    }

}